
#include "stdafx.h"
#include "WicStream.h"

//==============================================================================
// CWicStream
//==============================================================================

CWicStream::CWicStream()
{
    m_pIWICStream = NULL;
    g_theImagingFactory->CreateStream(&m_pIWICStream);
}

CWicStream::~CWicStream()
{
    if(m_pIWICStream)
    {
        m_pIWICStream->Release();
    }
    m_pIWICStream = NULL;
}

CWicStream::CWicStream(CWicStream const & objStream)
{
    m_pIWICStream = objStream.m_pIWICStream;
    m_pIWICStream->AddRef();
}

CWicStream& CWicStream::operator=(CWicStream const & objStream)
{
    if(m_pIWICStream)
    {
        m_pIWICStream->Release();
    }
    m_pIWICStream = objStream.m_pIWICStream;
    m_pIWICStream->AddRef();
    return *this;
}

//==============================================================================
// IWICStream
//==============================================================================
HRESULT STDMETHODCALLTYPE CWicStream::InitializeFromIStream( 
    /* [in] */ IStream *pIStream)
{
    return m_pIWICStream->InitializeFromIStream(pIStream);
}

HRESULT STDMETHODCALLTYPE CWicStream::InitializeFromFilename( 
    /* [in] */ __RPC__in LPCWSTR wzFileName,
    /* [in] */ DWORD dwDesiredAccess)
{
    return m_pIWICStream->InitializeFromFilename(wzFileName, dwDesiredAccess);
}

HRESULT STDMETHODCALLTYPE CWicStream::InitializeFromMemory( 
    /* [size_is][in] */ __RPC__in_ecount_full(cbBufferSize) BYTE *pbBuffer,
    /* [in] */ DWORD cbBufferSize)
{
    return m_pIWICStream->InitializeFromMemory(pbBuffer, cbBufferSize);
}

HRESULT STDMETHODCALLTYPE CWicStream::InitializeFromIStreamRegion( 
    /* [in] */ IStream *pIStream,
    /* [in] */ ULARGE_INTEGER ulOffset,
    /* [in] */ ULARGE_INTEGER ulMaxSize)
{
    return m_pIWICStream->InitializeFromIStreamRegion(pIStream, ulOffset, ulMaxSize);
}

//==============================================================================
// IStream
//==============================================================================
HRESULT STDMETHODCALLTYPE CWicStream::Seek( 
    /* [in] */ LARGE_INTEGER dlibMove,
    /* [in] */ DWORD dwOrigin,
    /* [out] */ ULARGE_INTEGER *plibNewPosition)
{
    return m_pIWICStream->Seek(dlibMove, dwOrigin, plibNewPosition);
}

HRESULT STDMETHODCALLTYPE CWicStream::SetSize(/* [in] */ ULARGE_INTEGER libNewSize)
{
    return m_pIWICStream->SetSize(libNewSize);
}

HRESULT STDMETHODCALLTYPE CWicStream::CopyTo( 
    /* [unique][in] */ IStream *pstm,
    /* [in] */ ULARGE_INTEGER cb,
    /* [out] */ ULARGE_INTEGER *pcbRead,
    /* [out] */ ULARGE_INTEGER *pcbWritten)
{
    return m_pIWICStream->CopyTo(pstm, cb, pcbRead, pcbWritten);
}

HRESULT STDMETHODCALLTYPE CWicStream::Commit(/* [in] */ DWORD grfCommitFlags)
{
    return m_pIWICStream->Commit(grfCommitFlags);
}

HRESULT STDMETHODCALLTYPE CWicStream::Revert()
{
    return m_pIWICStream->Revert();
}

HRESULT STDMETHODCALLTYPE CWicStream::LockRegion( 
    /* [in] */ ULARGE_INTEGER libOffset,
    /* [in] */ ULARGE_INTEGER cb,
    /* [in] */ DWORD dwLockType)
{
    return m_pIWICStream->LockRegion(libOffset, cb, dwLockType);
}

HRESULT STDMETHODCALLTYPE CWicStream::UnlockRegion( 
    /* [in] */ ULARGE_INTEGER libOffset,
    /* [in] */ ULARGE_INTEGER cb,
    /* [in] */ DWORD dwLockType)
{
    return m_pIWICStream->UnlockRegion(libOffset, cb, dwLockType);
}

HRESULT STDMETHODCALLTYPE CWicStream::Stat(
    /* [out] */ __RPC__out STATSTG *pstatstg,
    /* [in] */ DWORD grfStatFlag)
{
    return m_pIWICStream->Stat(pstatstg, grfStatFlag);
}

HRESULT STDMETHODCALLTYPE CWicStream::Clone( 
    /* [out] */ __RPC__deref_out_opt IStream **ppstm)
{
    return m_pIWICStream->Clone(ppstm);
}

//==============================================================================
// ISequentialStream
//==============================================================================
HRESULT STDMETHODCALLTYPE CWicStream::Read( 
    /* [length_is][size_is][out] */ void *pv,
    /* [in] */ ULONG cb,
    /* [out] */ ULONG *pcbRead)
{
    return m_pIWICStream->Read(pv, cb, pcbRead);
}

HRESULT STDMETHODCALLTYPE CWicStream::Write( 
    /* [size_is][in] */ const void *pv,
    /* [in] */ ULONG cb,
    /* [out] */ ULONG *pcbWritten)
{
    return m_pIWICStream->Write(pv, cb, pcbWritten);
}

